import Vue from "vue";
import Router from "vue-router";
import { Message } from "element-ui";
Vue.use(Router);
const login = () =>
    import ("@/views/login");
const lampPage = () =>
    import ("@/views/lampPage");
const loopPage = () =>
    import ("@/views/loopPage");
const MeteorologicalPage = () =>
    import ("@/views/MeteorologicalPage");
const ScreenNesting = () =>
    import ("@/views/ScreenNesting");
const wifiNesting = () =>
    import ("@/views/wifiNesting");
const steward = () =>
    import ("@/views/steward");
const electricityMapSingle = () =>
    import ("@/views/ElectricityMapSingle");
const map = () =>
    import ("@/components/map");
const distribution = () =>
    import ("../views/ElectricBox/distribution.vue");
const lamp = () =>
    import ("../views/StreetLamp/lamp.vue");
const BoxStrategy = () =>
    import ("../views/ElectricBox/ElectricBoxStrategy/BoxStrategy.vue");
const LntelligentAnalysis = () =>
    import ("@/views/LntelligentAnalysis");
const SetUp = () =>
    import ("@/views/system/SetUp");
const EquipmentLibrary = () =>
    import ("@/views/system/ElectricBox/DeviceManagement/EquipmentLibrary");
const groupmanagement = () =>
    import ("@/views/system/ElectricBox/Groupmanagement/groupmanagement");
const scene = () =>
    import ("../views/system/ElectricBox/ScenarioManagement/scene.vue");
const ElectricBoxStrategy = () =>
    import ("../views/system/ElectricBox/StrategyManagement/ElectricBoxStrategy.vue");

const lampStrategy = () =>
    import ("../views/system/lamp/StrategyManagement/lampStrategy.vue");



const userManagement = () =>
    import ("../views/system/userManagement/userManagement");
const setUser = () =>
    import ("../views/setUser.vue");
const setStrategy = () =>
    import ("../components/system/setStrategy/setStrategy.vue");
const Journal = () =>
    import ("../views/system/Journal/systemLog.vue");
const NotFound = () =>
    import ("../views/err.vue");
const MapPosition = () =>
    import ("../components/system/position.vue")
const lampGroupmanagement = () =>
    import ("../views/system/lamp/lampManagement/lampGroupmanagement.vue")
const LampEquipmentLibrary = () =>
    import ("../views/system/lamp/DeviceManagement/LampEquipmentLibrary.vue")
const lampScene = () =>
    import ("../views/system/lamp/sceneManagement/lampScene.vue")
const serverJump = () =>
    import ("../views/system/server/serverJump.vue")
const loopElectricCurrent = () =>
    import ("../views/ElectricBox/loopElectricCurrent")
const DeviceObject = () =>
    import ("../views/system/ElectricBox/DeviceManagement/DeviceObject.vue")
    // 充电桩
const BillManagement = () =>
    import ("../views/system/ChargingPile/bill/BillManagement")
const ChargingPileSystem = () =>
    import ("../views/system/ChargingPile/system/ChargingPileSystem")
const ChargingPileUser = () =>
    import ("../views/system/ChargingPile/ChargingPileUser/ChargingPileUser.vue")
const ChargingPilePage = () =>
    import ("@/views/ChargingPilePage/ChargingPilePage");
// 视频
const video = () =>
    import ("@/views/StreetLamp/video/videoHome");
const RadioIntercom = () =>
    import ("@/views/radioBroadcast/RadioIntercom");

// 音柱设备管理
const BroadcastingEquipment = () =>
    import ("../views/system/SoundColumn/BroadcastingEquipment.vue")
const BroadcastingGroup = () =>
    import ("../views/system/SoundColumn/BroadcastingGroup.vue")
const SoundStrategy = () =>
    import ("../views/system/SoundColumn/StrategyManagement/SoundStrategy.vue")
const setSoundStrategy = () =>
    import ("../views/system/SoundColumn/StrategyManagement/children/setSoundStrategy.vue")
const BroadcastingScene = () =>
    import ("../views/system/SoundColumn/BroadcastingScene.vue")
const MediaResourceManagement = () =>
    import ("../views/system/SoundColumn/MediaResourceManagement.vue")
    //  视频

const router = new Router({
    mode: "history",
    routes: [{
            name: "index",
            path: "/",
            dispatch: "/login",
            component: login
        },
        {
            path: "/DeviceObject",
            component: DeviceObject
        },
        {
            name: "login",
            path: "/login",
            component: login
        },
        {
            name: "steward",
            path: "/steward",
            component: steward
        },
        {
            path: "/lampPage",
            component: lampPage
        }, {
            path: "/loopPage",
            component: loopPage
        }, {
            path: "/MeteorologicalPage",
            component: MeteorologicalPage
        },
        {
            path: "/setUser",
            component: setUser
        }, {
            path: "/ChargingPilePage",
            component: ChargingPilePage
        },
        {
            path: "/electricityMapSingle",
            component: electricityMapSingle,
            children: [{
                    path: "/LntelligentAnalysis",
                    component: LntelligentAnalysis
                },
                {
                    path: "/distribution",
                    component: distribution
                }, {
                    path: "/ScreenNesting",
                    component: ScreenNesting
                }, {
                    path: "/wifiNesting",
                    component: wifiNesting
                },
                {
                    name: "lamp",
                    path: "/lamp",
                    component: lamp
                },
                {
                    path: "/BoxStrategy",
                    component: BoxStrategy
                }

            ]
        }, {
            path: "/loopElectricCurrent",
            component: loopElectricCurrent
        },
        {
            path: "/SetUp",
            component: SetUp,
            children: [{
                    path: "/EquipmentLibrary",
                    component: EquipmentLibrary
                },
                {
                    path: "/groupmanagement",
                    component: groupmanagement
                },
                {
                    path: "/scene",
                    component: scene
                },
                {
                    path: "/ElectricBoxStrategy",
                    component: ElectricBoxStrategy
                },
                {
                    path: "/userManagement",
                    component: userManagement
                },
                {
                    path: "/setStrategy",
                    component: setStrategy
                },
                {
                    path: "/Journal",
                    component: Journal
                }, {
                    path: "/MapPosition",
                    component: MapPosition
                }, {
                    path: "/lampGroupmanagement",
                    component: lampGroupmanagement
                }, {
                    path: "/LampEquipmentLibrary",
                    component: LampEquipmentLibrary

                }, {
                    path: "/lampScene",
                    component: lampScene
                }, {
                    path: "/serverJump",
                    component: serverJump
                },
                {
                    path: "/BillManagement",
                    component: BillManagement
                }, {

                    path: "/ChargingPileSystem",
                    component: ChargingPileSystem
                }, {
                    path: "/ChargingPileUser",
                    component: ChargingPileUser
                }, {
                    path: "/BroadcastingEquipment",
                    component: BroadcastingEquipment
                }, {
                    path: "/BroadcastingGroup",
                    component: BroadcastingGroup
                }, {
                    path: "/BroadcastingGroup",
                    component: BroadcastingGroup
                }, {
                    path: "/lampStrategy",
                    component: lampStrategy
                }, {
                    path: "/SoundStrategy",
                    component: SoundStrategy
                }, {
                    path: "/setSoundStrategy",
                    component: setSoundStrategy
                }, {
                    path: "/BroadcastingScene",
                    component: BroadcastingScene
                }, {
                    path: "/MediaResourceManagement",
                    component: MediaResourceManagement
                }

            ]
        },
        {
            name: "404",
            path: "*",
            component: NotFound,
        }
    ]
});
router.beforeEach((to, from, next) => {
    if (window.timer) {
        if (to.path != "/distribution") {
            clearInterval(window.timer);
        }
    }
    if (to.matched[0].path == "/SetUp") {
        if (sessionStorage.getItem("userRole") != 1) {
            router.push("NotFound")
            return
        }
    }
    if (to.name === "login" || to.name === "index") {
        next();
    } else {
        const token = sessionStorage.getItem("token");
        if (token) {
            next();
        } else if (!token) {
            Message.warning("请您先登录");
            router.push("/");
            return;
        }
    }
});
export default router;